#Twisted Shootout
#Copyright (C) 2007 Han Dao
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

#You can contact the author at wikipediankiba@gmail.com
import pygame
class MapEditChanger:
	def __init__(self,engine,sel):
		self.engine = engine
		self.sel = sel
		self.mode = 1
		self.old = 0
		self.object = pygame.Rect(0,0,80,60)
	def checkall(self,key):
		if self.window(key) == False:
			return
		rows = 0
		columns = 0
		n = 0
		while True:
			a = columns * 80 + self.engine.position.move
			b = rows * 60 + self.engine.position.height
			self.object.x = a
			self.object.y = b
			self.determine(n,key)
			columns = columns + 1
			n = n + 1
			if columns == 30:
				rows = rows + 1
				columns = 0
			if rows == 30:
				return
	def determine(self,n,key):
		if self.object.colliderect(key):
			self.activate(n)
	def activate(self,n):
		if self.mode == 1:
			self.engine.obj[0][n] = self.sel.value
		elif self.mode == 2:
			self.engine.obj[0][n] = 0
			self.engine.mapobj[self.old].image = self.sel.blank.image
			self.old = n
			self.engine.obj[1] = [self.object.x,self.object.y]
		elif self.mode == 3:
			self.engine.obj[0][n] = 0
			self.engine.mapobj[n].image = self.sel.blank.image
			if self.sel.value == 9:
				self.engine.obj[2][n] = 1
			elif self.sel.value == 10:
				self.engine.obj[2][n] = 2
			self.engine.items.items = []
			self.engine.items.datacompute()
			return
		self.engine.mapobj[n].image = self.sel.current.image
	def window(self,key):
		size = pygame.Rect(0,0,800,600)
		if size.colliderect(key):
			return True
		return False